/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package graphviewer;

import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Sabitov Artem
 * @since 21.09.2013
 */
public class Edge extends JPanel {
	private Node n1;
	private Node n2;
	
	@Override
    protected void paintComponent(Graphics g) {
		super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.drawLine((int)n1.getCoordX(), (int)n1.getCoordY(), (int)n2.getCoordX(), (int)n2.getCoordY());
		g2d.drawLine((int)n2.getCoordX(), (int)n2.getCoordY(), (int)n1.getCoordX(), (int)n1.getCoordY());
		// #remake
		setBounds(0, 0, 1024, 768);
	}
	
	public Edge(Node n1, Node n2) {
		this.n1 = n1;
		this.n2 = n2;
		setBackground(Color.RED);
		setOpaque(false);//(Debug.getStateDebugComponent());
		// #remake
		setBounds(0, 0, 1024, 768);
	}
	
	public Edge() {
	}
	
	public boolean checkEdge(Node nodeToCheck) {
		if(n2.equals(nodeToCheck)) {
			return true;
		} else if(n1.equals(nodeToCheck)) {
			return true;
		} else return false;
	}
	
	protected void update() {
		repaint();
		// #remake
		setBounds(0, 0, 1024, 768);
	}
}
